﻿<?php
/**
 * 显示管理用户答题界面
 *
 * @author kinet <380511703@qq.com>
 * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
 */
session_start();
require_once( 'path.php' );
require_once( SOJ_ROOT.'/include/function/lib.php');
require_once('Pager.php');

$tpl = new my_smarty();

//若未登录,则重定向到登录界面
if( empty($_SESSION['admin']) ){

	$_SESSION['success_message'] = 'do not login yet , '.$_SESSION['admin'];
	header( 'Location:../manager/manager_login.php' );
	exit ;
}
$request = $_GET;

if( empty( $request['name']) ){
	//用户名,直接跳转到user页面
	header( 'Location:../manager/manager_user.php' );
	exit ;
}else{
	$username = $request['name'];
}

//处理由其他页面保存在会话中的错误信息
if( !empty($_SESSION['errors']) ){

	$tpl->assign( 'errors' , $_SESSION['errors']  );
	//清除之前的错误信息
	unset( $_SESSION['errors'] );
}
$tpl->assign('admin', $_SESSION['admin']);
try{
	$db = db_connect();
	$user_problem_result= new judge_result_process( $db );
	$results=$user_problem_result->get_all_result_by_username($username);
	if ( empty($results) ){//结果为空跳回用户界面
	     echo "<script language=\"JavaScript\">\r\n"; 
		 echo " alert(\"用户没有答题\");\r\n"; 
		 echo " history.back();\r\n"; 
		 echo "</script>"; 
		 exit; 
	}
	//动态获得结果数组的键名
	$titles = array_keys($results[0] );
	$results_num = count( $results );

	//此配置应该可以由配置文件读出
	$params = array(
    		'itemData' =>$results,
    		'perPage' => 30,
    		'delta' => 8,
    		'append' => true,
    		'clearIfVoid' => false,
    		'urlVar' => 'entrant',
    		'useSessions' => true,
    		'closeSession' => true,
    		'mode'  => 'Jumping',
	);

	$pager = & Pager::factory($params);
	$page_data = $pager->getPageData();
	$links = $pager->getLinks();

//	$selectBox = $pager->getPerPageSelectBox();
    $tpl->assign( 'username' , $username );
	$tpl->assign( 'titles' , $titles );
	$tpl->assign( 'results_num' , $results_num );
	$tpl->assign( 'results' , $page_data );
	$tpl->assign( 'links' , $links['all'] );
	$tpl->display('manager_user_problems.tpl');

}catch(Exception $e){
	exception_handle( $e );
}

